/*
读取bag文件
*/

#include "ros/ros.h"
#include "rosbag/bag.h"
#include "std_msgs/String.h"
#include "rosbag/view.h"
#include "std_msgs/Int32.h"

int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");
    ros::init(argc, argv, "bag_read");
    ros::NodeHandle nh;
    // 1.创建rosbag对象
    rosbag::Bag bag;
    // 2.打开文件流
    bag.open("chatter.bag", rosbag::BagMode::Read);
    // 3.读取话题数据
    for (auto &m : rosbag::View(bag))
    {
        //解析数据并打印
        std::string topic = m.getTopic();
        ros::Time time = m.getTime();
        std_msgs::StringConstPtr p = m.instantiate<std_msgs::String>();
        ROS_INFO("读取的数据是。话题：%s;时间：%.2f;内容：%s.",
                 topic.c_str(),
                 time.toSec(),
                 p->data.c_str());
    }
    // 4.关闭文件流
    bag.close();
    return 0;
}



